#!/usr/bin/env python
# coding: utf-8
# @Time    : 2021/11/17 11:50
# @Author  : YD
# @Email   : dinhe_1985@126.com
# @File    : add_hosts_from_csv.py
# @Software: PyCharm
# @Blog    : www.noteshare.cn

from conf.api_conf import ZABBIX_SERVER, ZABBIX_USER, ZABBIX_PASSWORD
from lib.zbx_api import AutoZabbix
from lib.zbx_log import LoggingRecord

logger = LoggingRecord('file_console_logger', 'info')

zabbix = AutoZabbix(ZABBIX_SERVER, ZABBIX_USER, ZABBIX_PASSWORD)

with open(file='zbx_import_template.csv', mode='r', encoding='gbk') as f:
    for line_num, csv_info in enumerate(f):
        #跳过第一行
        if line_num == 0:
            continue
        host_info = csv_info.split(',')
        host_ip = host_info[0].strip()
        host_name = host_info[1].strip()
        host_group = host_info[2].strip()
        host_os = host_info[3].strip()
        host_active = host_info[4].strip()
        zbx_version = host_info[5].strip()
        zabbix.create_host(host_name=host_name, host_ip=host_ip, host_group=host_group, zbx_version=zbx_version,
                           host_os=host_os, active=host_active)

